﻿using System;
using System.Web;
using System.Diagnostics;
using System.IdentityModel.Selectors;
using System.ServiceModel;
using Ninject;
using Persistance;

namespace WebServices.Infrastructure
{
    public class CustomValidator : UserNamePasswordValidator
    {
        [Inject]
        public IGestionCompte GestionCompte { get; set; }

        /// <summary>
        /// Validate the username and password token
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        public override void Validate(string userName, string password)
        {
            if (GestionCompte == null)
                GestionCompte = new GestionCompte();

            if (!GestionCompte.LogIn(userName, password))
                throw new Exception("Utilisateur inconnu");

            HttpContext.Current.Session["login"] = userName;
        }
    }
}